home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
cug106
/
ntoi.c
< prev
next >
Wrap
Text File
|
1984-06-14
|
2KB
|
70 lines
/*
this function converts ascii characters to an integer.
most common number bases may be used (except offset
octal).
*/
ntoi(n,b)
char *n;
int b;
{
int val,sign;
char c;
val=0; sign=1;
while ((c = *n) == '\t' || c == ' ') ++n;
if (c == '-') {sign = -1; n++;}
while (dig(c = *n++)) {
if (b == 16 && c >= 'A' && c <= 'F') c -= 7;
val = val * b + c - '0';
}
return sign*val;
}
/*
otoi(n)
this function converts an offset octal number in ASCII
to an integer. the number is in the format xxx.xxx{a} and
may be preceeded by white space.
*/
otoi(n)
char *n;
{
int val, b, i;
char c;
val = 0; b = 16384;
while ((c = *n) == '\t' || c == ' ') ++n;
for (i = 0; i < 7; i++) {
if ((c = *n) == '.') {++n; b = 64;}
else {c = *n++; val = val + (b * (c - '0')); b /= 8;}
}
return val;
}
/*------------------------------------------------------------------*/
/* */
/* This is a library of private routines for use with BDS C prog- */
/* grams. The comment lines preceding each entry are intended */
/* to give a sufficient explanation of the routine that follows. */
/* To link any of these routines to a BDS C program, merely name */
/* PRVLIB as a argument following the name of the main program in */
/* the CLINK command line. */
/* */
/*------------------------------------------------------------------*/
/*
Move k bytes from blk1 to blk2.
The two blocks may overlap.
Since k must be positive, this routine is limited to
moving blocks less than 32k in length.
Added by M. Goldberg, 25-DEC-79.
*/
movblk(blk1, blk2, k)
char *blk1, *blk2;
int k;
{
int m,